package com.zp.self.module.spring常用.国际化;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ：byH
 * @date ：Created 2022/1/16 22:47
 * @description：国际化测试
 */
@RestController
@RequestMapping("/i18n")
public class I18nController {
    @Resource
    I18nService i18nService;

    //获取普通词汇翻译
    @GetMapping("/translate-content")
    public ResponseEntity translateContent(@RequestParam(name = "content") String content,
                                           @RequestParam(name = "param" ,required = false) Object[] param) {
        return ResponseEntity.ok(i18nService.getMessage(content, param));
    }

    //获取异常code 翻译
    @GetMapping("/translate-exception")
    public ResponseEntity translateException(@RequestParam(name = "content") String content,
                                           @RequestParam(name = "param" ,required = false) Object[] param) {
        return ResponseEntity.ok(i18nService.getExceptionMessage(content, param));
    }

    @GetMapping("/hello-coder")
    public ResponseEntity greeting() {
        return ResponseEntity.ok(i18nService.getMessage("message.key.hello", new Object[]{"JavaCoder"}));
    }

    @GetMapping("/test")
    public ResponseEntity test() {
        return ResponseEntity.ok(i18nService.getMessage("message.key.test"));
    }

}
